package main

import (
	"bww/en"
	"encoding/json"
	"fmt"
	"io/ioutil"
	"net/http"
)

var conf config

type config struct {
	Default string `json:"default"`
	Items []item `json:"items"`
}

type item struct {
	Host string `json:"host"`
	Url string `json:"url"`
}

func init() {
	b, _ := ioutil.ReadFile(".json")
	json.Unmarshal(b, &conf)
	fmt.Println("urlistener - bi202111031003", "\n", en.Sign())
}

func jump(w http.ResponseWriter, r *http.Request) {
	url := conf.Default

	for _, i := range conf.Items {
		if (r.Host == i.Host) {
			url = i.Url
			break
		}
	}

	http.Redirect(w, r, url, http.StatusFound)
}

func main() {
	http.HandleFunc("/", jump)
	http.ListenAndServe(":80", nil)
}